create filter by attribute (my code)

$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'forme_shape');


foreach ($attribute->getSource()->getAllOptions(true, true) as $instance) {

    // $myArray[$instance['value']] = $instance['label'];
    //$productCollection_shape=
    $category_shape=Mage::getModel('catalog/category')->load($idcats);
    $productCollection_qty = $category_shape->getProductCollection()
        ->addAttributeToSelect(array('name', 'forme_shape'))
        ->addAttributeToFilter('forme_shape', array('eq' =>$instance['value'] ))
        ->count();
   //print_r($productCollection_qty);
   if($productCollection_qty>0)
   {
       $myArray[$instance['value']] = $instance['label'];
   }
}
//print_r($myArray);

Leave a Comment